<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" >
    <meta http-equiv="X-UA-Compatible" content="IE=11,IE=10,IE=9,IE=8" >
    <meta name="baidu-site-verification" content="dIcXMeY8Ya" />
    
    <title>Kotlin/Java解析XMl文件的四种方式 | 即将拥有人鱼线丶</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" >
    <meta name="keywords" content="FutaoSmile丶, 前端, Web, 付韬, 后端开发, Kotlin" >
    <meta name="description" content="FutaoSmile丶" >

    
    <link rel="alternative" href="/atom.xml" title="即将拥有人鱼线丶" type="application/atom+xml" >
    
    
    <link rel="shortcut icon" href="/coder957/favicon.ico" >
    
    <link rel="stylesheet" href="/coder957/css/style.css">
    <!--[if lt IE 9]>
    <script src="/coder957/js/html5.js"></script>
    <![endif]-->
    
<script>
    var _hmt = _hmt || [];
    (function() {
        var hm = document.createElement("script");
        hm.src = "//hm.baidu.com/hm.js?fd459238242776d173cdc64918fb32f2";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
</script>


</head>

<body class="home">
    <!--[if lt IE 9]>
    <div class="browsehappy">
        当前网页 <strong>不支持</strong>
        你正在使用的浏览器. 为了正常的访问, 请 <a href="http://browsehappy.com/">升级你的浏览器</a>.
    </div>
    <![endif]-->

    <!-- 博客头部 -->
    <header class="header">
    <section class="container header-main">
        <div class="logo">
            <a href="/coder957/">
                <div class="cover">
                    <span class="name">即将拥有人鱼线丶</span>
                    <span class="description"></span>
                </div>
            </a>
        </div>
        <div class="dropnav icon-paragraph-justify" id="JELON__btnDropNav"></div>
        <ul class="menu hidden" id="JELON__menu">
            
            <li rel="/coder957/2017/11/02/java读取xml/index.html" class="item ">
                <a href="/coder957/" title="首页" class="icon-home">&nbsp;首页</a>
            </li>
            
            <li rel="/coder957/2017/11/02/java读取xml/index.html" class="item ">
                <a href="/coder957/lab/" title="实验室" class="icon-lab">&nbsp;实验室</a>
            </li>
            
            <li rel="/coder957/2017/11/02/java读取xml/index.html" class="item ">
                <a href="/coder957/about/" title="关于" class="icon-about">&nbsp;关于</a>
            </li>
            
            <li rel="/coder957/2017/11/02/java读取xml/index.html" class="item ">
                <a href="/coder957/comment/" title="留言" class="icon-comment">&nbsp;留言</a>
            </li>
            
        </ul>
        <div class="profile clearfix">
            <div class="feeds fl">
                
                
                <p class="links">
                    
                        <a href="https://github.com/FutaoSmile" target="_blank">Github</a>
                        |
                    
                        <a href="http://www.jianshu.com/u/9e2e579df7dd" target="_blank">简书</a>
                        
                    
                </p>
                <p class="sns">
                    
                        <a href="" class="sinaweibo" target="_blank"><b>■</b> 新浪微博</a>
                    
                        <a href="https://gitee.com/FutaoSmile" class="qqweibo" target="_blank"><b>■</b> 码云</a>
                    
                    <!---->
                    <!--<a href="javascript: void(0);" class="wechat">-->
                        <!--<b>■</b>-->
                        <!--公众号-->
                        <!--<span class="popover">-->
                            <!--<img src="/coder957/img/wechat_mp.jpg" width="120" height="120" alt="我的微信订阅号">-->
                            <!--<i class="arrow"></i>-->
                        <!--</span>-->
                    <!--</a>-->
                </p>
                
            </div>
            <div class="avatar fr">
                <img src="/coder957/img/jelon.jpg" alt="avatar" title="FutaoSmile丶" >
            </div>
        </div>
    </section>
</header>


    <!-- 博客正文 -->
    <div class="container body clearfix">
        <section class="content">
            <div class="content-main widget">
                <!-- 文章页 -->
<!-- 文章 -->
<article class="post article">
    <header class="text-center">
        <h3 class="post-title"><span>Kotlin/Java解析XMl文件的四种方式</span></h3>
    </header>
    <p class="post-meta text-center">
        FutaoSmile丶 发表于
        <time datetime="2017-11-02T09:20:49.000Z">2017-11-02</time>
    </p>
    <div class="post-content">
        <p>des…</p>
<blockquote>
<p>四种解析方式：</p>
<ol>
<li>DOM</li>
<li>SAX</li>
<li>JDOM</li>
<li>DOM4J</li>
</ol>
</blockquote>
<a id="more"></a>
<p><strong>Maven依赖</strong><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">&lt;!--解析xml--&gt;</div><div class="line"> &lt;!-- https://mvnrepository.com/artifact/org.jdom/jdom --&gt;</div><div class="line"> &lt;dependency&gt;</div><div class="line">     &lt;groupId&gt;org.jdom&lt;/groupId&gt;</div><div class="line">     &lt;artifactId&gt;jdom&lt;/artifactId&gt;</div><div class="line">     &lt;version&gt;2.0.2&lt;/version&gt;</div><div class="line"> &lt;/dependency&gt;</div><div class="line"></div><div class="line"> &lt;!-- https://mvnrepository.com/artifact/dom4j/dom4j --&gt;</div><div class="line"> &lt;dependency&gt;</div><div class="line">     &lt;groupId&gt;dom4j&lt;/groupId&gt;</div><div class="line">     &lt;artifactId&gt;dom4j&lt;/artifactId&gt;</div><div class="line">     &lt;version&gt;1.6.1&lt;/version&gt;</div><div class="line"> &lt;/dependency&gt;</div></pre></td></tr></table></figure></p>
<h3 id="解析目标-books-xml文件"><a href="#解析目标-books-xml文件" class="headerlink" title="解析目标-books.xml文件"></a>解析目标-books.xml文件</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;</div><div class="line">&lt;books&gt;</div><div class="line">    &lt;book id=&quot;1&quot;&gt;</div><div class="line">        &lt;name&gt;XML深入浅出&lt;/name&gt;</div><div class="line">        &lt;author&gt;Imooc&lt;/author&gt;</div><div class="line">        &lt;year&gt;2014&lt;/year&gt;</div><div class="line">        &lt;price&gt;89&lt;/price&gt;</div><div class="line">    &lt;/book&gt;</div><div class="line">    &lt;book id=&quot;2&quot;&gt;</div><div class="line">        &lt;name&gt;Java从入门到精通&lt;/name&gt;</div><div class="line">        &lt;author&gt;Imooc&lt;/author&gt;</div><div class="line">        &lt;price&gt;369&lt;/price&gt;</div><div class="line">    &lt;/book&gt;</div><div class="line">&lt;/books&gt;</div></pre></td></tr></table></figure>
<h3 id="1-DOM方式解析"><a href="#1-DOM方式解析" class="headerlink" title="1. DOM方式解析"></a>1. DOM方式解析</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div></pre></td><td class="code"><pre><div class="line">package imooc</div><div class="line"></div><div class="line">import org.junit.Test</div><div class="line">import org.xml.sax.SAXException</div><div class="line">import java.io.IOException</div><div class="line">import javax.xml.parsers.DocumentBuilderFactory</div><div class="line">import javax.xml.parsers.ParserConfigurationException</div><div class="line">import javax.xml.soap.Node</div><div class="line"></div><div class="line">/**</div><div class="line"> * @author futao</div><div class="line"> * Created on 2017/11/2 - 18:19.</div><div class="line"> */</div><div class="line">class XML &#123;</div><div class="line">    @Test</div><div class="line">    fun DOM() &#123;</div><div class="line">        //1.创建一个DocumentBuilderFactory对象</div><div class="line">        val builderFactory = DocumentBuilderFactory.newInstance()</div><div class="line">        try &#123;</div><div class="line">            //2.创建一个DocumentBuilder</div><div class="line">            val documentBuilder = builderFactory.newDocumentBuilder()</div><div class="line">            //通过DocumentBuilder对象的parse方法加载books.xml到当前项目下</div><div class="line">            val parse = documentBuilder.parse(&quot;D:\\src\\springhibernate\\springshibernate\\src\\test\\kotlin\\imooc\\books.xml&quot;)</div><div class="line">            //获取节点(book)的集合</div><div class="line">            val bookNodeList = parse.getElementsByTagName(&quot;book&quot;)</div><div class="line"></div><div class="line">            println(&quot;book节点个数为$&#123;bookNodeList.length&#125;&quot;)</div><div class="line">            //遍历每一个book节点</div><div class="line">            for (i in 0 until bookNodeList.length) &#123;</div><div class="line">                //遍历每个book节点的所有属性的集合</div><div class="line">                val bookNodeAttributes = bookNodeList.item(i).attributes</div><div class="line">                for (j in 0 until bookNodeAttributes.length) &#123;</div><div class="line">                    println(&quot;第$&#123;i + 1&#125; 个book节点公有$&#123;bookNodeList.item(i).attributes.length&#125;个属性&quot;)</div><div class="line">                    println(&quot;属性：&quot; + bookNodeAttributes.item(j))</div><div class="line">                    println(bookNodeAttributes.item(j).nodeName)</div><div class="line">                    println(bookNodeAttributes.item(j).nodeValue)</div><div class="line"></div><div class="line">                    //获取当前book节点的子节点集合</div><div class="line">                    val bookNodeChildNodes = bookNodeList.item(i).childNodes</div><div class="line">                    //会把空格和换行符也当成节点</div><div class="line">                    println(&quot;第$&#123;i + 1&#125; 本书共有$&#123;(bookNodeChildNodes.length - 1) / 2&#125;个子节点&quot;)</div><div class="line">//                    for (k in 0 until (bookNodeChildNodes.length - 1) / 2) &#123;</div><div class="line">                    (0 until bookNodeChildNodes.length - 1)</div><div class="line">                            .filter &#123; bookNodeChildNodes.item(it).nodeType == Node.ELEMENT_NODE &#125;</div><div class="line">                            .forEach &#123;</div><div class="line">                                print(&quot;子节点&quot; + bookNodeChildNodes.item(it).nodeName)</div><div class="line">                                //null</div><div class="line">//                                println(bookNodeChildNodes.item(it).nodeValue)</div><div class="line">                                println(&quot;   对应的值为   &quot; + bookNodeChildNodes.item(it).firstChild.nodeValue)</div><div class="line">//                                println(&quot;   对应的值为   &quot; + bookNodeChildNodes.item(it).textContent)</div><div class="line">                            &#125;</div><div class="line">                &#125;</div><div class="line">            &#125;</div><div class="line">        &#125; catch (e: ParserConfigurationException) &#123;</div><div class="line">            e.printStackTrace()</div><div class="line">        &#125; catch (e: IOException) &#123;</div><div class="line">            e.printStackTrace()</div><div class="line">        &#125; catch (e: SAXException) &#123;</div><div class="line">            e.printStackTrace()</div><div class="line">        &#125;</div><div class="line"></div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p><strong>结果</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">book节点个数为2</div><div class="line">第1 个book节点公有1个属性</div><div class="line">属性：id=&quot;1&quot;</div><div class="line">id</div><div class="line">1</div><div class="line">第1 本书共有4个子节点</div><div class="line">子节点name   对应的值为   XML深入浅出</div><div class="line">子节点author   对应的值为   Imooc</div><div class="line">子节点year   对应的值为   2014</div><div class="line">子节点price   对应的值为   89</div><div class="line">第2 个book节点公有1个属性</div><div class="line">属性：id=&quot;2&quot;</div><div class="line">id</div><div class="line">2</div><div class="line">第2 本书共有3个子节点</div><div class="line">子节点name   对应的值为   Java从入门到精通</div><div class="line">子节点author   对应的值为   Imooc</div><div class="line">子节点price   对应的值为   369</div></pre></td></tr></table></figure>
<hr>
<h3 id="2-SAX方式解析"><a href="#2-SAX方式解析" class="headerlink" title="2.SAX方式解析"></a>2.SAX方式解析</h3><p><strong>Book.class</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">package imooc;</div><div class="line"></div><div class="line">/**</div><div class="line"> * @author futao</div><div class="line"> * Created on 2017/11/3 - 11:05.</div><div class="line"> */</div><div class="line">public class Book &#123;</div><div class="line">    private int id;</div><div class="line">    private String name;</div><div class="line">    private String author;</div><div class="line">    private String year;</div><div class="line">    private String price;</div><div class="line"></div><div class="line">    public int getId() &#123;</div><div class="line">        return id;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setId(int id) &#123;</div><div class="line">        this.id = id;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public String getName() &#123;</div><div class="line">        return name;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setName(String name) &#123;</div><div class="line">        this.name = name;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public String getAuthor() &#123;</div><div class="line">        return author;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setAuthor(String author) &#123;</div><div class="line">        this.author = author;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public String getYear() &#123;</div><div class="line">        return year;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setYear(String year) &#123;</div><div class="line">        this.year = year;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public String getPrice() &#123;</div><div class="line">        return price;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public void setPrice(String price) &#123;</div><div class="line">        this.price = price;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div></pre></td><td class="code"><pre><div class="line">    @Test</div><div class="line">    fun bySAX() &#123;</div><div class="line">        val sAXParserFactory = SAXParserFactory.newInstance()</div><div class="line">        val sAXParser = sAXParserFactory.newSAXParser()</div><div class="line">        //需要编写处理类MySAXParserHandler</div><div class="line">        sAXParser.parse(&quot;D:\\src\\springhibernate\\springshibernate\\src\\test\\kotlin\\imooc\\books.xml&quot;, MySAXParserHandler())</div><div class="line"></div><div class="line">    &#125;</div><div class="line"></div><div class="line"></div><div class="line">    </div><div class="line">class MySAXParserHandler : DefaultHandler() &#123;</div><div class="line">    //遍历xml的book节点的索引</div><div class="line">    private var bookIndex = 0</div><div class="line">    //保存book对象</div><div class="line">    private var bookList = ArrayList&lt;Book&gt;()</div><div class="line">    //当前的book对象</div><div class="line">    var book = Book()</div><div class="line">    //当前文本内容</div><div class="line">    var trim = &quot;&quot;</div><div class="line"></div><div class="line">    /**</div><div class="line">     * 遍历xml的文件开始标签</div><div class="line">     */</div><div class="line">    override fun startElement(uri: String?, localName: String?, qName: String?, attributes: Attributes?) &#123;</div><div class="line">        super.startElement(uri, localName, qName, attributes)</div><div class="line">        if (qName!! == &quot;book&quot;) &#123;</div><div class="line">            book = Book()</div><div class="line">            bookList.add(book)</div><div class="line">            bookIndex++</div><div class="line">            println(&quot;开始遍历第$bookIndex 本书&quot;)</div><div class="line">//            val value = attributes!!.getValue(&quot;id&quot;)</div><div class="line">//            println(value)</div><div class="line">            for (i in 0 until attributes!!.length) &#123;</div><div class="line">                print(&quot;属性名为：&quot; + attributes.getQName(i))</div><div class="line">                println(&quot;属性值为：&quot; + attributes.getValue(i))</div><div class="line">                book.id = attributes.getValue(i).toInt()</div><div class="line">            &#125;</div><div class="line">        &#125; else if (qName != &quot;book&quot; &amp;&amp; qName != &quot;books&quot;) &#123;</div><div class="line">            print(&quot;子节点名字为：   $qName    子节点的值为：     &quot;)</div><div class="line">        &#125;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    /**</div><div class="line">     * 遍历xml文件的结束标签</div><div class="line">     */</div><div class="line">    override fun endElement(uri: String?, localName: String?, qName: String?) &#123;</div><div class="line">        super.endElement(uri, localName, qName)</div><div class="line">        when (qName) &#123;</div><div class="line">            &quot;name&quot; -&gt; book.name = trim</div><div class="line">            &quot;author&quot; -&gt; book.author = trim</div><div class="line">            &quot;year&quot; -&gt; book.year = trim</div><div class="line">            &quot;price&quot; -&gt; book.price = trim</div><div class="line">        &#125;</div><div class="line">        if (qName == &quot;book&quot;) &#123;</div><div class="line">            println(&quot;========================第$bookIndex 本书遍历完成&quot;)</div><div class="line">        &#125;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    /**</div><div class="line">     * 标志解析开始</div><div class="line">     */</div><div class="line">    override fun startDocument() &#123;</div><div class="line">        super.startDocument()</div><div class="line">        println(&quot;SAX解析开始...&quot;)</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    /**</div><div class="line">     * 标志解析结束</div><div class="line">     */</div><div class="line">    override fun endDocument() &#123;</div><div class="line">        super.endDocument()</div><div class="line">        println(&quot;SAX解析结束...&quot;)</div><div class="line">        println(GsonBuilder().serializeNulls().setPrettyPrinting().create().toJson(bookList))</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    /**</div><div class="line">     * 解析内容，获取文本</div><div class="line">     */</div><div class="line">    override fun characters(ch: CharArray?, start: Int, length: Int) &#123;</div><div class="line">        super.characters(ch, start, length)</div><div class="line">        val strings = String(ch!!, start, length)</div><div class="line">        trim = strings.trim()</div><div class="line">        if (trim != &quot;&quot;) &#123;</div><div class="line">            println(trim)</div><div class="line">        &#125;</div><div class="line">    &#125;</div></pre></td></tr></table></figure>
<p><strong>结果</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div></pre></td><td class="code"><pre><div class="line">SAX解析开始...</div><div class="line">开始遍历第1 本书</div><div class="line">属性名为：id属性值为：1</div><div class="line">子节点名字为：   name    子节点的值为：     XML深入浅出</div><div class="line">子节点名字为：   author    子节点的值为：     Imooc</div><div class="line">子节点名字为：   year    子节点的值为：     2014</div><div class="line">子节点名字为：   price    子节点的值为：     89</div><div class="line">========================第1 本书遍历完成</div><div class="line">开始遍历第2 本书</div><div class="line">属性名为：id属性值为：2</div><div class="line">子节点名字为：   name    子节点的值为：     Java从入门到精通</div><div class="line">子节点名字为：   author    子节点的值为：     Imooc</div><div class="line">子节点名字为：   price    子节点的值为：     369</div><div class="line">========================第2 本书遍历完成</div><div class="line">SAX解析结束...</div><div class="line">[</div><div class="line">  &#123;</div><div class="line">    &quot;id&quot;: 1,</div><div class="line">    &quot;name&quot;: &quot;XML深入浅出&quot;,</div><div class="line">    &quot;author&quot;: &quot;Imooc&quot;,</div><div class="line">    &quot;year&quot;: &quot;2014&quot;,</div><div class="line">    &quot;price&quot;: &quot;89&quot;</div><div class="line">  &#125;,</div><div class="line">  &#123;</div><div class="line">    &quot;id&quot;: 2,</div><div class="line">    &quot;name&quot;: &quot;Java从入门到精通&quot;,</div><div class="line">    &quot;author&quot;: &quot;Imooc&quot;,</div><div class="line">    &quot;year&quot;: null,</div><div class="line">    &quot;price&quot;: &quot;369&quot;</div><div class="line">  &#125;</div><div class="line">]</div></pre></td></tr></table></figure>
<hr>
<h3 id="3-JDOM"><a href="#3-JDOM" class="headerlink" title="3.JDOM"></a>3.JDOM</h3><p><strong>Maven依赖</strong><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">&lt;!-- https://mvnrepository.com/artifact/org.jdom/jdom --&gt;</div><div class="line">     &lt;dependency&gt;</div><div class="line">         &lt;groupId&gt;org.jdom&lt;/groupId&gt;</div><div class="line">         &lt;artifactId&gt;jdom&lt;/artifactId&gt;</div><div class="line">         &lt;version&gt;2.0.2&lt;/version&gt;</div><div class="line">     &lt;/dependency&gt;</div></pre></td></tr></table></figure></p>
<p><strong>主要代码</strong><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div></pre></td><td class="code"><pre><div class="line">package imooc.imooc.jdom</div><div class="line"></div><div class="line">import com.google.gson.GsonBuilder</div><div class="line">import imooc.Book</div><div class="line">import org.jdom2.input.SAXBuilder</div><div class="line">import org.junit.Test</div><div class="line">import java.io.FileInputStream</div><div class="line">import java.io.InputStreamReader</div><div class="line"></div><div class="line">/**</div><div class="line"> * @author futao</div><div class="line"> * Created on 2017/11/3 - 13:41.</div><div class="line"> */</div><div class="line">class Jdom &#123;</div><div class="line">    @Test</div><div class="line">    fun testJdom() &#123;</div><div class="line">        val list = ArrayList&lt;Book&gt;()</div><div class="line">        var book = Book()</div><div class="line">        //1.创建一个SAXBuilder对象</div><div class="line">        val saxBuilder = SAXBuilder()</div><div class="line">        /*</div><div class="line">        * 乱码解决方案</div><div class="line">        * 1.修改xml文件的编码格式</div><div class="line">        * 2.用InputStreamReader代替FileInputStream，设置编码格式</div><div class="line">        * */</div><div class="line">        //2.通过输入流的方式加载xml文件到saxBuilder中</div><div class="line">//        val document = saxBuilder.build(FileInputStream(&quot;D:\\src\\springhibernate\\springshibernate\\src\\test\\resources\\books.xml&quot;))</div><div class="line">        val document = saxBuilder.build(InputStreamReader(FileInputStream(&quot;D:\\src\\springhibernate\\springshibernate\\src\\test\\resources\\books.xml&quot;), &quot;UTF-8&quot;))</div><div class="line">        //3.获取根节点</div><div class="line">        val rootElement = document.rootElement</div><div class="line">        //4.根节点的子节点集合</div><div class="line">        val rootChildElement = rootElement.children</div><div class="line">        for (i in rootChildElement) &#123;</div><div class="line">            println(&quot;==================== 开始解析第$&#123;rootChildElement.indexOf(i) + 1&#125;本书==================== &quot;)</div><div class="line">            book = Book()</div><div class="line">            //解析根节点的所有属性</div><div class="line">            for (k in i.attributes) &#123;</div><div class="line">                println(k.name + &quot;   ：   &quot; + k.value)</div><div class="line">                assignment(book, k.name, k.value)</div><div class="line">            &#125;</div><div class="line">            val children = i.children</div><div class="line">            //解析子节点和子节点的内容</div><div class="line">            for (j in children) &#123;</div><div class="line">                println(j.name + &quot;  :   &quot; + j.value)</div><div class="line">                assignment(book, j.name, j.value)</div><div class="line">            &#125;</div><div class="line">            list.add(book)</div><div class="line">        &#125;</div><div class="line">        println(GsonBuilder().serializeNulls().setPrettyPrinting().create().toJson(list))</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    private fun assignment(book: Book, property: String, value: String): Book &#123;</div><div class="line">        when (property) &#123;</div><div class="line">            &quot;id&quot; -&gt; book.id = value.toInt()</div><div class="line">            &quot;name&quot; -&gt; book.name = value</div><div class="line">            &quot;author&quot; -&gt; book.author = value</div><div class="line">            &quot;year&quot; -&gt; book.year = value</div><div class="line">            &quot;price&quot; -&gt; book.price = value</div><div class="line">        &#125;</div><div class="line">        return book</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p><strong>结果</strong><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div></pre></td><td class="code"><pre><div class="line">==================== 开始解析第1本书==================== </div><div class="line">id   ：   1</div><div class="line">name  :   XML深入浅出</div><div class="line">author  :   Imooc</div><div class="line">year  :   2014</div><div class="line">price  :   89</div><div class="line">==================== 开始解析第2本书==================== </div><div class="line">id   ：   2</div><div class="line">name  :   Java从入门到精通</div><div class="line">author  :   Imooc</div><div class="line">price  :   369</div><div class="line"></div><div class="line">Disconnected from the target VM, address: &apos;127.0.0.1:59271&apos;, transport: &apos;socket&apos;</div><div class="line">[</div><div class="line">  &#123;</div><div class="line">    &quot;id&quot;: 1,</div><div class="line">    &quot;name&quot;: &quot;XML深入浅出&quot;,</div><div class="line">    &quot;author&quot;: &quot;Imooc&quot;,</div><div class="line">    &quot;year&quot;: &quot;2014&quot;,</div><div class="line">    &quot;price&quot;: &quot;89&quot;</div><div class="line">  &#125;,</div><div class="line">  &#123;</div><div class="line">    &quot;id&quot;: 2,</div><div class="line">    &quot;name&quot;: &quot;Java从入门到精通&quot;,</div><div class="line">    &quot;author&quot;: &quot;Imooc&quot;,</div><div class="line">    &quot;year&quot;: null,</div><div class="line">    &quot;price&quot;: &quot;369&quot;</div><div class="line">  &#125;</div><div class="line">]</div></pre></td></tr></table></figure></p>
<h3 id="4-DOM4J"><a href="#4-DOM4J" class="headerlink" title="4.DOM4J"></a>4.DOM4J</h3><p><strong>maven依赖</strong><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">&lt;!-- https://mvnrepository.com/artifact/dom4j/dom4j --&gt;</div><div class="line">&lt;dependency&gt;</div><div class="line">    &lt;groupId&gt;dom4j&lt;/groupId&gt;</div><div class="line">    &lt;artifactId&gt;dom4j&lt;/artifactId&gt;</div><div class="line">    &lt;version&gt;1.6.1&lt;/version&gt;</div><div class="line">&lt;/dependency&gt;</div></pre></td></tr></table></figure></p>
<p><strong>主要代码</strong><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div></pre></td><td class="code"><pre><div class="line">package imooc.imooc.dom4j</div><div class="line"></div><div class="line">import com.google.gson.GsonBuilder</div><div class="line">import imooc.Book</div><div class="line">import org.dom4j.Attribute</div><div class="line">import org.dom4j.Element</div><div class="line">import org.dom4j.io.SAXReader</div><div class="line">import org.junit.Test</div><div class="line">import java.io.File</div><div class="line"></div><div class="line">/**</div><div class="line"> * @author futao</div><div class="line"> * Created on 2017/11/3 - 14:37.</div><div class="line"> */</div><div class="line">class DOM4JTest &#123;</div><div class="line">    @Test</div><div class="line">    fun testDOM4J() &#123;</div><div class="line">        val list = ArrayList&lt;Book&gt;()</div><div class="line">        var book = Book()</div><div class="line"></div><div class="line">        val saxReader = SAXReader()</div><div class="line">        val document = saxReader.read(File(&quot;D:\\src\\springhibernate\\springshibernate\\src\\test\\resources\\books.xml&quot;))</div><div class="line">        //根节点</div><div class="line">        val rootElement = document.rootElement</div><div class="line">        //通过Element的elementIterator()方法获取迭代器</div><div class="line">        val elementIterator = rootElement.elementIterator()</div><div class="line">        //遍历迭代器，获取根节点的子节点信息</div><div class="line">        for ((index, i) in elementIterator.withIndex()) &#123;</div><div class="line">            val element = i as Element</div><div class="line">//            println(element.name)</div><div class="line">            println(&quot;===============开始解析第$&#123;index + 1&#125;本书===============&quot;)</div><div class="line">            book = Book()</div><div class="line">            //遍历子节点的属性</div><div class="line">            i.attributes()</div><div class="line">                    .map &#123; it as Attribute &#125;</div><div class="line">                    .forEach &#123;</div><div class="line">                        println(it.name + &quot;    :   &quot; + it.value)</div><div class="line">                        assignment(book, it.name, it.value)</div><div class="line">                    &#125;</div><div class="line">            //遍历子节点的子节点和内容</div><div class="line">            for (k in i.elementIterator()) &#123;</div><div class="line">                k as Element</div><div class="line">                println(k.name + &quot;    :   &quot; + k.textTrim)</div><div class="line">                assignment(book, k.name, k.textTrim)</div><div class="line">            &#125;</div><div class="line">            list.add(book)</div><div class="line">        &#125;</div><div class="line">        println(GsonBuilder().serializeNulls().setPrettyPrinting().create().toJson(list))</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    private fun assignment(book: Book, property: String, value: String): Book &#123;</div><div class="line">        when (property) &#123;</div><div class="line">            &quot;id&quot; -&gt; book.id = value.toInt()</div><div class="line">            &quot;name&quot; -&gt; book.name = value</div><div class="line">            &quot;author&quot; -&gt; book.author = value</div><div class="line">            &quot;year&quot; -&gt; book.year = value</div><div class="line">            &quot;price&quot; -&gt; book.price = value</div><div class="line">        &#125;</div><div class="line">        return book</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p><strong>结果</strong><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div></pre></td><td class="code"><pre><div class="line">===============开始解析第1本书===============</div><div class="line">id    :   1</div><div class="line">name    :   deep</div><div class="line">name    :   XML深入浅出</div><div class="line">author    :   Imooc</div><div class="line">year    :   2014</div><div class="line">price    :   89</div><div class="line">===============开始解析第2本书===============</div><div class="line">id    :   2</div><div class="line">name    :   Java从入门到精通</div><div class="line">author    :   Imooc</div><div class="line">price    :   369</div><div class="line">[</div><div class="line">  &#123;</div><div class="line">    &quot;id&quot;: 1,</div><div class="line">    &quot;name&quot;: &quot;XML深入浅出&quot;,</div><div class="line">    &quot;author&quot;: &quot;Imooc&quot;,</div><div class="line">    &quot;year&quot;: &quot;2014&quot;,</div><div class="line">    &quot;price&quot;: &quot;89&quot;</div><div class="line">  &#125;,</div><div class="line">  &#123;</div><div class="line">    &quot;id&quot;: 2,</div><div class="line">    &quot;name&quot;: &quot;Java从入门到精通&quot;,</div><div class="line">    &quot;author&quot;: &quot;Imooc&quot;,</div><div class="line">    &quot;year&quot;: null,</div><div class="line">    &quot;price&quot;: &quot;369&quot;</div><div class="line">  &#125;</div><div class="line">]</div></pre></td></tr></table></figure></p>
<h3 id="读取效率"><a href="#读取效率" class="headerlink" title="读取效率"></a>读取效率</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div></pre></td><td class="code"><pre><div class="line">@Test</div><div class="line">fun efficiencyCompare() &#123;</div><div class="line">    val startTime1 = System.currentTimeMillis()</div><div class="line">    testDOM4J()</div><div class="line">    println(&quot;DOM4J耗时: $&#123;System.currentTimeMillis() - startTime1&#125;&quot;)</div><div class="line"></div><div class="line"></div><div class="line">    val startTime2 = System.currentTimeMillis()</div><div class="line">    Jdom().testJdom()</div><div class="line">    println(&quot;JDOM耗时: $&#123;System.currentTimeMillis() - startTime2&#125;&quot;)</div><div class="line"></div><div class="line">    val startTime3 = System.currentTimeMillis()</div><div class="line">    XML().byDOM()</div><div class="line">    println(&quot;DOM耗时: $&#123;System.currentTimeMillis() - startTime3&#125;&quot;)</div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line">    val startTime4 = System.currentTimeMillis()</div><div class="line">    XML().bySAX()</div><div class="line">    println(&quot;SAX耗时: $&#123;System.currentTimeMillis() - startTime4&#125;&quot;)</div><div class="line"></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p><strong>结果</strong><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">DOM4J耗时: 379</div><div class="line">JDOM耗时: 141</div><div class="line">DOM耗时: 52</div><div class="line">SAX耗时: 32</div></pre></td></tr></table></figure></p>

    </div>
    <p class="post-meta">
        <span class="post-cat">分类：
            <a class="cat-link" href="/coder957/categories/BackEnd/">BackEnd</a>
        </span>
        <span class="post-tags">
            标签：
            
    
        <a href="/coder957/tags/Kotlin/" title="Kotlin">Kotlin</a> / 
    
        <a href="/coder957/tags/XML/" title="XML">XML</a>
    

        </span>
    </p>
</article>
<!-- 分享按钮 -->

  <div class="article-share clearfix text-center">
    <div class="share-area">
      <span class="share-txt">分享到：</span>
      <a href="javascript: window.open('http://service.weibo.com/share/share.php?url=' + encodeURIComponent(location.href) + '&title=' + document.title + '&language=zh_cn');" class="share-icon weibo"></a>
      <a href="javascript: alert('请复制链接到微信并发送');" class="share-icon wechat"></a>
      <a href="javascript: window.open('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + encodeURIComponent(location.href) + '&title=' + document.title);" class="share-icon qqzone"></a>
      <a href="javascript: window.open('http://connect.qq.com/widget/shareqq/index.html?url=' + encodeURIComponent(location.href) + '&desc=Jelon个人博客&title=' + document.title + '&callback=' + encodeURIComponent(location.href));" class="share-icon qq"></a>
      <a href="javascript: window.open('http://shuo.douban.com/!service/share?href=' + encodeURIComponent(location.href) + '&name=' + document.title + '&text=' + document.title);" class="share-icon douban"></a>
    </div>
  </div>


<!-- 上一篇/下一篇 -->

<div class="article-nav clearfix">
    
    <span class="prev fl">
        上一篇<br >
        <a href="/coder957/2017/11/08/kotlin-java生成xml/">
            
                kotlin/java生成xml
            
        </a>
    </span>
    

    
    <span class="next fr">
        下一篇<br >
        <a href="/coder957/2017/10/20/COMMANDS/">
            
                SOME USEFUL GIT COMMANDS
            
        </a>
    </span>
    
</div>

<!-- 文章评论 -->

  <script src="/coder957/js/comment.js"></script>
  <div id="comments" class="comment">
    <!--
    <div class="sign-bar">
      GitHub 已登录!
      <span class="sign-link">登出</span>
    </div>
    <section class="box">
      <div class="com-avatar"><img src="/img/jelon.jpg" alt="avatar"></div>
      <div class="com-text">
        <div class="main">
          <textarea class="text-area-edited show" placeholder="欢迎评论！"></textarea>
          <div class="text-area-preview"></div>
        </div>
        <div class="switch">
          <div class="switch-item on">编辑</div>
          <div class="switch-item">预览</div>
        </div>
        <div class="button">提交</div>
      </div>
    </section>
    <section class="tips">注：评论支持 markdown 语法！</section>
    <section class="list-wrap">
      <ul class="list">
        <li>
          <div class="user-avatar">
            <a href="/">
              <img src="/img/jelon.jpg" alt="user-avatar">
            </a>
          </div>
          <div class="user-comment">
            <div class="user-comment-header">
              <span class="post-name">张德龙</span>
              <span class="post-time">2017年12月12日</span>
              <span class="like liked">已赞</span>
              <span class="like-num">2</span>
            </div>
            <div class="user-comment-body">333333</div>
          </div>
        </li>
        <li>
          <div class="user-avatar">
            <a href="/">
              <img src="/img/jelon.jpg" alt="user-avatar">
            </a>
          </div>
          <div class="user-comment">
            <div class="user-comment-header">
              <span class="post-name">刘德华</span>
              <span class="post-time">2017年12月12日</span>
              <span class="like">点赞</span>
              <span class="like-num">2</span>
            </div>
            <div class="user-comment-body">vvvvv</div>
          </div>
        </li>
      </ul>
      <div class="page-nav">
        <a href="javascript: void(0);" class="item">1</a>
        <a href="javascript: void(0);" class="item">2</a>
        <a href="javascript: void(0);" class="item current">3</a>
      </div>
    </section>
    -->
  </div>
  <script>
  JELON.Comment({
    container: 'comments',
    label: 'java读取xml' || '2017/11/02/java读取xml/',
    owner: 'FutaoSmile',
    repo: 'blog_comments',
    clientId: '149ec394071cfd7f0f47',
    clientSecret: 'd1c988f53efa3f0f8651799f8212cc8e2cab24b9'
  });
  </script>


            </div>

        </section>
        <!-- 侧栏部分 -->
<aside class="sidebar">
    <section class="widget">
        <h3 class="widget-hd"><strong>文章分类</strong></h3>
        <!-- 文章分类 -->
<ul class="widget-bd">
    
    <li>
        <a href="/coder957/categories/BackEnd/">BackEnd</a>
        <span class="badge">(19)</span>
    </li>
    
    <li>
        <a href="/coder957/categories/All/">All</a>
        <span class="badge">(2)</span>
    </li>
    
    <li>
        <a href="/coder957/categories/FrontEnd/">FrontEnd</a>
        <span class="badge">(1)</span>
    </li>
    
</ul>
    </section>

    
    <section class="widget">
        <h3 class="widget-hd"><strong>热门标签</strong></h3>
        <!-- 文章标签 -->
<div class="widget-bd tag-wrap">
  
    <a class="tag-item" href="/coder957/tags/Kotlin/" title="Kotlin">Kotlin (13)</a>
  
    <a class="tag-item" href="/coder957/tags/Git/" title="Git">Git (1)</a>
  
    <a class="tag-item" href="/coder957/tags/Java/" title="Java">Java (6)</a>
  
    <a class="tag-item" href="/coder957/tags/Collections/" title="Collections">Collections (1)</a>
  
    <a class="tag-item" href="/coder957/tags/Maven/" title="Maven">Maven (3)</a>
  
    <a class="tag-item" href="/coder957/tags/Hibernate/" title="Hibernate">Hibernate (2)</a>
  
    <a class="tag-item" href="/coder957/tags/Spring/" title="Spring">Spring (9)</a>
  
    <a class="tag-item" href="/coder957/tags/JSON/" title="JSON">JSON (1)</a>
  
    <a class="tag-item" href="/coder957/tags/XML/" title="XML">XML (1)</a>
  
    <a class="tag-item" href="/coder957/tags/热点文章/" title="热点文章">热点文章 (1)</a>
  
    <a class="tag-item" href="/coder957/tags/博主推荐/" title="博主推荐">博主推荐 (1)</a>
  
    <a class="tag-item" href="/coder957/tags/Ajax/" title="Ajax">Ajax (1)</a>
  
    <a class="tag-item" href="/coder957/tags/设计模式/" title="设计模式">设计模式 (1)</a>
  
    <a class="tag-item" href="/coder957/tags/资料/" title="资料">资料 (1)</a>
  
    <a class="tag-item" href="/coder957/tags/转载/" title="转载">转载 (1)</a>
  
</div>
    </section>
    

    

    
    <!-- 友情链接 -->
    <section class="widget">
        <h3 class="widget-hd"><strong>友情链接</strong></h3>
        <!-- 文章分类 -->
<ul class="widget-bd">
    
        <li>
            <a href="http://blog.sina.com.cn/u/1825875765" target="_blank" title="friendLink01">友情链接</a>
        </li>
    
        <li>
            <a href="http://blog.csdn.net/yeweiouyang" target="_blank" title="friendLink02">友情链接</a>
        </li>
    
        <li>
            <a href="http://xuanzh.cc/" target="_blank" title="friendLink03">友情链接</a>
        </li>
    
</ul>
    </section>
    
</aside>
<!-- / 侧栏部分 -->
    </div>

    <!-- 博客底部 -->
    <footer class="footer">
    &copy;
    
        2016-2017
    

    <a href="/coder957/">Peace and Love</a>
</footer>
<div class="back-to-top" id="JELON__backToTop" title="返回顶部">返回顶部</div>

    <!--博客js脚本 -->
    <!-- 这里放网站js脚本 -->
<script src="/coder957/js/main.js"></script>
</body>
</html>